<%@ page import="java.text.DateFormat" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: 86155
  Date: 2021/10/15
  Time: 13:31
  To change this template use File | Settings | File Templates.
--%>
<%request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=UTF-8");%>
<%//日期时间
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CHINA);
DateFormat df2 = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.CHINA);
String date = df.format(new Date());
String time = df2.format(new Date());
//聊天内容
String chatInfo = request.getParameter("chatInfo");
    System.out.println("聊天内容："+chatInfo);
if(chatInfo != null && !"".equals(chatInfo)){
    if(application.getAttribute("chatInfo") == null){
        StringBuffer info = new StringBuffer();
        info.append(session.getAttribute("uname")+" "+date+" "+time);
        info.append("::");
        info.append(chatInfo);
        application.setAttribute("chatInfo",info);
        //System.out.println(info.toString());
    }else{
        StringBuffer info = (StringBuffer) application.getAttribute("chatInfo");
        info.append("|");
        info.append(session.getAttribute("uname")+" "+date+" "+time);
        info.append("::");
        info.append(chatInfo);
        application.setAttribute("chatInfo",info);
        //System.out.println(info.toString());
    }
    application.setAttribute("flag",true);
}
    //System.out.println("聊天内容1："+(StringBuffer) application.getAttribute("chatInfo"));
    response.sendRedirect("chat.jsp");%>

